package com.rdzn.mall.center.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.rdzn.mall.center.entity.UmsMember;
import com.rdzn.mall.center.mapper.UmsMemberMapper;
import com.rdzn.mall.center.service.IUmsMemberService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


/**
 * @Description: ums_member
 * @Author: jeecg-boot
 * @Date:   2020-08-27
 * @Version: V1.0
 */

@Service
public class UmsMemberServiceImpl extends ServiceImpl<UmsMemberMapper, UmsMember> implements IUmsMemberService {

    @Override
    public UmsMember getByWeXinOpenId(String openId) {
        return getOne(new LambdaQueryWrapper<UmsMember>().eq(UmsMember::getWeixinOpenid, openId));
    }

    @Override
    public UmsMember getByInvitationCode(String invitationCode) {
        return getOne(new LambdaQueryWrapper<UmsMember>().eq(UmsMember::getInvitationCode, invitationCode));
    }

    @Override
    public void updateIntegration(Integer id, Integer integration) {
        UmsMember record=new UmsMember();
        record.setId(id);
        record.setIntegration(integration);
        updateById(record);
    }

//    @Override
//    public MemberDetails loginOrRegisterUser(UmsMember umsMember, String invitationCode) {
//        UmsMember umsMember1 = this.getByWeXinOpenId(umsMember.getWeixinOpenid());
//        if (null == umsMember1) {
//            if (StringUtils.isNotEmpty(invitationCode)){
//                UmsMember invitor = this.getByInvitationCode(invitationCode);
//                if (invitor != null){
//                    umsMember.setParentUserId(invitor.getId());
//                }
//            }
//            umsMember.setInvitationCode(UUID.randomUUID().toString().replaceAll("-","").toUpperCase());
//            umsMember.setCreateTime(new Date());
//            this.save(umsMember);
//            return new MemberDetails(umsMember);
//        }
//        return new MemberDetails(umsMember1);
//    }
}
